package com.zpz.framework.zpzoauth.common.utils;

import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zhangpanzhi
 * @time 2019-07-09
 * @description 未经本人允许请勿随便改动，尊重劳动
 * */
public class ZpzOauthListUtil <T> {
    /**
     *
     * @param list 要拆分的集合
     * @param size 指定的大小
     * @return
     */
    public  List<List<T>> getSplitList(List<T> list , int size)
    {
        List<List<T>> returnList = new ArrayList<List<T>>();
        int listSize = list.size();
        int num = listSize%size==0?listSize/size:(listSize/size+1);
        int start = 0;
        int end = 0;
        for(int i=1;i<=num;i++)
        {
            start = (i-1)*size;
            end = i*size>listSize?listSize:i*size;
            System.out.println(start+":"+end);
            returnList.add(list.subList(start, end));
        }
        return returnList;
    }
    public static List copyListProperties(List<? extends Object> sources, Class target, String... ignoreProperties) {
        List targets = new ArrayList();
        Object obj = null;
        for (Object source : sources) {
            try {
                obj = target.newInstance();
            } catch (InstantiationException | IllegalAccessException e) {
                e.printStackTrace();
            }
            BeanUtils.copyProperties(source, obj,ignoreProperties);
            targets.add(obj);
        }
        return targets;
    }
}
